import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

import 'chrome_safari_browser_example.screen.dart';
import 'headless_in_app_webview.screen.dart';
import 'in_app_browser_example.screen.dart';
import 'in_app_webiew_example.screen.dart';



class InnerWebPage extends StatefulWidget {
  @override
  _InnerWebPageState createState() => _InnerWebPageState();
}

class _InnerWebPageState extends State<InnerWebPage> {

  @override
  void initState() {
    super.initState();
    init();
  }

  init() async {
    WidgetsFlutterBinding.ensureInitialized();
    // await Permission.camera.request();
    // await Permission.microphone.request();
    // await Permission.storage.request();

    if (Platform.isAndroid) {
      await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true);

      var swAvailable = await AndroidWebViewFeature.isFeatureSupported(
          AndroidWebViewFeature.SERVICE_WORKER_BASIC_USAGE);
      var swInterceptAvailable = await AndroidWebViewFeature.isFeatureSupported(
          AndroidWebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST);

      if (swAvailable && swInterceptAvailable) {
        AndroidServiceWorkerController serviceWorkerController =
        AndroidServiceWorkerController.instance();

        serviceWorkerController.serviceWorkerClient = AndroidServiceWorkerClient(
          shouldInterceptRequest: (request) async {
            print(request);
            return null;
          },
        );
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('inappwebview'),
      ),
      body: SafeArea(
        child: Column(children: [
          ListTile(
            title: Text('111'),
            onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (context) => InAppWebViewExampleScreen()),);
            },
          ),
          ListTile(
            title: Text('222'),
            onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (context) => InAppBrowserExampleScreen()),);
            },
          ),
          ListTile(
            title: Text('333'),
            onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (context) => ChromeSafariBrowserExampleScreen()),);
            },
          ),
          ListTile(
            title: Text('444'),
            onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (context) => HeadlessInAppWebViewExampleScreen()),);
            },
          ),

        ],),
      ),
    );
  }


}

Drawer myDrawer({required BuildContext context}) {
  return Drawer(
    child: ListView(
      padding: EdgeInsets.zero,
      children: <Widget>[
        DrawerHeader(
          child: Text('flutter_inappbrowser example'),
          decoration: BoxDecoration(
            color: Colors.blue,
          ),
        ),
        ListTile(
          title: Text('InAppBrowser'),
          onTap: () {
            Navigator.pushReplacementNamed(context, '/InAppBrowser');
          },
        ),
        ListTile(
          title: Text('ChromeSafariBrowser'),
          onTap: () {
            Navigator.pushReplacementNamed(context, '/ChromeSafariBrowser');
          },
        ),
        ListTile(
          title: Text('InAppWebView'),
          onTap: () {
            Navigator.pushReplacementNamed(context, '/');
          },
        ),
        ListTile(
          title: Text('HeadlessInAppWebView'),
          onTap: () {
            Navigator.pushReplacementNamed(context, '/HeadlessInAppWebView');
          },
        ),
      ],
    ),
  );
}